﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
namespace Demo.View
{
    /// <summary>
    /// CustomRibbonView.xaml 的交互逻辑
    /// </summary>
    public partial class CustomRibbonView : Autodesk.Windows.RibbonTab {
        public CustomRibbonView()
        {
            this.Id = Guid.NewGuid().ToString();
            InitializeComponent();
        }
    }

    public class CustomRibbonViewModel : ViewModelBase {
        private string _BtnName;
        public string BtnName {
            get { return _BtnName; }
            set { Set(ref _BtnName, value); }
        }

        public CustomRibbonViewModel()
        {
            _BtnName = "画线";
        }

        private RelayCommand<object>? _BtnCmd;

        public RelayCommand<object> BtnCmd {
            get { return _BtnCmd ??= new RelayCommand<object>(ExecuteMyCmdCmd); }
        }

        private void ExecuteMyCmdCmd(object? obj) {
            if(obj is Autodesk.Windows.RibbonCommandItem item) {
                string? cmdStr = item.CommandParameter?.ToString();
                if (!string.IsNullOrWhiteSpace(cmdStr)) {
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument?
                                .SendStringToExecute($"\u001b{cmdStr}\n", true, false, true);
                }
            }
        }


    }

}
